package com.chenwang.measure.ui.adapter;

import android.support.annotation.Nullable;
import android.support.constraint.ConstraintLayout;
import android.text.TextUtils;
import android.view.View;
import android.widget.CheckBox;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chenwang.measure.R;
import com.chenwang.measure.model.bean.CustomBean;


import java.util.List;

/**
 * @松 on 2019/7/18 09:50
 *  上传下载适配器
 */
public class FreedomAdapter extends BaseQuickAdapter <CustomBean,BaseViewHolder>{
    public FreedomAdapter(@Nullable List<CustomBean> data) {
        super(R.layout.item_freedom, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, final CustomBean item) {
        helper.setText(R.id.tv_name, item.getUserId()+"      "+item.getStartName()+"——"+item.getEndName());
        final CheckBox cb = helper.getView(R.id.cb);
        TextView state = helper.getView(R.id.tv_state);
        ConstraintLayout cl =helper.getView(R.id.cl);
        helper.addOnClickListener(R.id.tv_name);
        cb.setChecked(item.isSelect());
        cb.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                item.setSelect(cb.isChecked());
            }
        });
        switch (item.getState()){
            case 0:
                state.setText("新建");
                cl.setBackgroundResource(R.drawable.corners6_s1);
                cb.setVisibility(View.INVISIBLE);
                break;
            case 1:
                state.setText("待上传");
                cl.setBackgroundResource(R.drawable.corners6_s1_red);
                cb.setVisibility(View.VISIBLE);
                break;
            case 2:
                state.setText("已完成");
                cl.setBackgroundResource(R.drawable.corners6_s1_bule);
                cb.setVisibility(View.VISIBLE);
                break;
        }
        if (!TextUtils.isEmpty(item.getDistance())){
           helper.setText(R.id.tv_distance,item.getDistance() );
        }else {
            helper.setText(R.id.tv_distance,"" );
        }

    }
}
